package controller.compare;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dbsync4j.mapper.behavior.compare.DifferenceCompare;

public class CompareDatabaseDetail extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		DifferenceCompare[] result = (DifferenceCompare[]) req.getSession(false).getAttribute("resultadoComparacao");		
		String index = req.getParameter("number");
		String view = req.getParameter("view");
		
		int index_ = Integer.valueOf(index);
			
		String dispatcher = "/jsp/comparedetail.jsp";
		
		if(view.equals("1")) {
			
			req.setAttribute("differences", result[index_].diff());
			
		} else if(view.equals("2")) {
		
		}
		
		RequestDispatcher requestDispatcher = req.getRequestDispatcher(dispatcher);
		requestDispatcher.forward(req, resp);
	}

}
